package projetofinal.wsdl2js.js;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URI;

import projetofinal.wsdl2js.exception.ExceptionHandler;
import projetofinal.wsdl2js.util.Indent;

@SuppressWarnings("serial")
public class JSFile extends File {
	
	public JSFile (String aFileName) {
		super (aFileName + ".js");
		ind = new Indent();
	}
	
	public JSFile(File aParent, String aChild) {
		super(aParent, aChild + ".js");
		ind = new Indent();
	}

	public JSFile(String aParent, String aChild) {
		super(aParent, aChild + ".js");
		ind = new Indent();
	}

	public JSFile(URI uri) {
		super(uri); // ver depois
		ind = new Indent();
	}
	
	public void createOrOverwriteFile () {
		if (this.exists()) {
			this.delete();
		}
		try {
			this.createNewFile();
		} catch (IOException ioe) {
			ExceptionHandler.handle(ioe);
		}
	}
	
	public void writeln (String aString) {
//		Args.checkForContent(aString); Aqui tava dando problema quando eu tento criar uma linha com string em branco
		
		try {
			BufferedWriter bw = new BufferedWriter (new FileWriter(this, true));
			bw.write(ind.str(aString));
			bw.newLine();
			bw.close();
		} catch (IOException ioe) {
			ExceptionHandler.handle(ioe);
		}
		
	}
	
	// PRIVATE //
	
	private Indent ind;

}
